package com.example.tests;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import com.example.fw.Folders;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

public class TestFolderCreation extends TestBase {
    Random rnd = new Random();
    
//	@Test
	public void testFolderCreation(){
		String folder = "newFolder";
		Folders oldFolders = app.getFolderHelper().getFolders(); 
		app.getFolderHelper().createFolder(folder);
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder)));
	}
//	@Test
	public void testVariuosFoldersCreation(){
		String folder1 = "newFolder1";
		String folder2 = "newFolder2";
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder1), is(nullValue()));
		
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder1)));
		assertThat(app.getFolderHelper().createFolder(folder2), is(nullValue()));
		app.getFolderHelper().createFolder(folder2);
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(newFolders.withAdded(folder2)));
	}
//	@Test
	public void testVariuosFoldersWithTheSameNameCreation(){
		String folder = "newFolder3";
//		String folder2 = "newFolder3";
		Folders oldFolders = app.getFolderHelper().getFolders(); 
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder)));
		assertThat(app.getFolderHelper().createFolder(folder), containsString("Duplicated folder name"));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(newFolders));
	}


	@Test
	public void testFolderRemoval(Object[] anyFolder){
        Folders oldFolders = app.getFolderHelper().getFolders();
        int i = new Random().nextInt(oldFolders.size());
        app.getFolderHelper().deleteFolder(i);
        Folders newFolders = app.getFolderHelper().getFolders();
        assertThat(newFolders, equalTo(oldFolders.without(i)));
        		
//		assertThat(oldFolders, equalTo(newFolders.withAdded(anyFolder)));	
		
	}
}
